# This file is part of BlackArch Linux ( http://blackarch.org ).
# See COPYING for license details.

pkgname=clair
pkgver=2130.7c9c079b
pkgrel=1
groups=('blackarch' 'blackarch-scanner')
pkgdesc='Vulnerability Static Analysis for Containers.'
arch=('x86_64' 'aarch64')
url='https://github.com/quay/clair'
license=('APACHE')
depends=('glibc' 'rpm-tools')
makedepends=('git' 'go')
source=("git+https://github.com/quay/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

build() {
  cd $pkgname

  GOPATH="$srcdir" go mod download
  GOPATH="$srcdir" go build \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags "-s -w" \
    -o $pkgname ./cmd/$pkgname

  GOPATH="$srcdir" go build \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags "-s -w" \
    -o clairctl ./cmd/clairctl
}


package() {
  cd $pkgname

  install -dm 755 "$pkgdir/etc/clair"

  install -Dm 755 $pkgname "$pkgdir/usr/bin/$pkgname"
  install -Dm 755 clairctl "$pkgdir/usr/bin/clairctl"
  install -Dm 644 -t "$pkgdir/etc/clair/" *.yaml *.yaml.sample
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname" *.md NOTICE
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  cp -r --no-preserve=ownership Documentation/* "$pkgdir/usr/share/doc/$pkgname/"
  cp "$pkgdir/etc/clair/config.yaml.sample" "$pkgdir/etc/clair/config.yaml"
}

